<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>等差数列生成器</title>
    <style>
        /* 页面样式 */
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f7fc;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            color: #333;
        }

        .container {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            text-align: center;
            width: 400px;
        }

        h1 {
            color: #4CAF50;
            font-size: 24px;
        }

        .input-group {
            margin: 15px 0;
        }

        input[type="number"] {
            padding: 10px;
            font-size: 16px;
            width: 150px;
            margin-right: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #45a049;
        }

        .result {
            margin-top: 20px;
            padding: 15px;
            font-size: 18px;
            border-radius: 4px;
            display: inline-block;
            background-color: #f1f1f1;
            color: #333;
        }

        .sequence {
            font-size: 20px;
            color: #4CAF50;
            margin-top: 15px;
            font-weight: bold;
        }

        .error {
            background-color: #f44336;
            color: white;
        }

        .info {
            background-color: #ff9800;
            color: white;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>等差数列生成器</h1>
        <div class="input-group">
            <label for="n">公差 (n):</label>
            <input type="number" id="n" placeholder="输入公差" min="1">
        </div>
        <div class="input-group">
            <label for="limit">最大值 (limit):</label>
            <input type="number" id="limit" placeholder="输入最大值" min="1">
        </div>
        <button onclick="generateSequence()">生成等差数列</button>
        <div id="result" class="result"></div>
    </div>

    <script>
        // 等差数列生成函数
        const arithmeticProgression = (n, limit) =>
            Array.from({ length: Math.ceil(limit / n) }, (_, i) => (i + 1) * n);

        // 生成等差数列并显示
        function generateSequence() {
            // 获取输入的公差 (n) 和最大值 (limit)
            const n = parseInt(document.getElementById('n').value);
            const limit = parseInt(document.getElementById('limit').value);

            // 获取结果显示区域
            const resultElement = document.getElementById('result');

            // 检查输入是否合法
            if (isNaN(n) || isNaN(limit) || n <= 0 || limit <= 0) {
                resultElement.textContent = "请输入有效的正整数！";
                resultElement.className = "result error";
            } else {
                // 使用等差数列函数生成数列
                const sequence = arithmeticProgression(n, limit);
                resultElement.textContent = "生成的等差数列是：";
                resultElement.className = "result info";
                const sequenceElement = document.createElement('div');
                sequenceElement.className = "sequence";
                sequenceElement.textContent = sequence.join(", ");
                resultElement.appendChild(sequenceElement);
            }
        }
    </script>
</body>

</html>